#include <bits/stdc++.h>
using namespace std;
int T,n,m,l,v,yy[100005],a,b,c,i,j,k=0,a1[100005],a2[100005],csd,a11=0,n1;
short xx[1000005];
struct stru{
    int x,y;
}zz[100005];
bool cmp(stru x,stru y){
    x.x<y.x;
}
void sfcs(){
    int x;
    if(c==0){
        if(b>v){
            a1[++a11]=a;
        }
        return;
    }
    double x1;
    x1=(v*v-b*b)/2*a;
    x=int(x1);
    if(c>0){
        x++;
        if(a+x<=l){
            a1[++a11]=a+x;//include a1
        }
        return;
    }
    if(b>v){
        if (x1-x==0)x--;
        if(a+x>=l)a1[++a11]=a;
        else zz[++k].x=a,zz[k].y=a+x;
    }
    return;
}
int bbd(int x,int l,int r){
    int mid=(l+r)/2;
    if(yy[mid]>x&&yy[mid-1]<=x)return mid-1;
    if(yy[mid]<x)return bbd(x,mid,r);
    return bbd(x,l,mid);
}
void wscsd(){
    int x,y;
    memset(a1,0,sizeof a1);
    for(i=1;i<=k;i++){
        x=bbd(zz[i].x,1,m+1);
        y=bbd(zz[i].y,1,m+1);
        if(x<y&&zz[k].x<=yy[m]){
            csd++;
            if(a1[x]==0||a2[x]==0)a1[x]++,a2[y]++;
        }
        else swap(zz[i].x,zz[k].x),swap(zz[i--].y,zz[k--].y);
    }
}
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    scanf("%d",&T);
    while(T--){
        csd=0;
        scanf("%d%d%d%d",&n,&m,&l,&v),n1=m;
        for(i=1;i<=n;i++){
            scanf("%d%d%d",&a,&b,&c);
            sfcs();//shifouchaosu
        }
        for(i=1;i<=m;i++){
            scanf("%d",&yy[i]);
        }
        a=100000001;
        for(i=1;i<=a11;i++){
            if(a1[i]<=yy[m])csd++;
            if(a1[i]<=a)a=a1[i];
        }
        m=bbd(a,1,m+1);
        wscsd();
        sort(zz+1,zz+1+k,cmp);
        a=0;
        for(i=m;i>0;i--){
            if(a1[i]!=0||a2[i]!=0){
                if(b==-1)b++;
                b+=a2[i]-a1[i];
            }
            if(a1[i]==0&&a2[i]==0)m--;
            else{
                if(b==0)b=-1,a++;
            }
        }
        printf("%d%d",csd,n1-m+a);
    }
    return 0;
}
